home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / texts / rdhtml2g.lha / RDHTML2AG next >
Text File  |  1996-04-16  |  6KB  |  214 lines

  1.  
  2. /*
  3.     RexxDoesHTML2AmigaGuide V0.9, 14 Apr 1996 by Michael Ranner
  4.     RexxDoesHTML2AmigaGuide V1.0, 15 Apr 1996 by Michael Ranner
  5.     RexxDoesHTML2AmigaGuide V1.1, 16 Apr 1996 by Michael Ranner
  6.     This piece of code is Public Domain. Use it, distribute it, modify it!
  7. */
  8.  
  9. arg src opt
  10.  
  11. if index(opt, '?') ~= 0 then do
  12.     say 'Source/A'
  13.     exit
  14. end
  15.  
  16. open('HTML', src, 'R')
  17. name = left(src, lastpos('.', src)) || 'guide'
  18. open('Guide', name,'W')
  19.  
  20. writeln('Guide', '@DATABASE ' || src)
  21. writeln('Guide', '@REMARK Converted by RexxDoesHTML2AmigaGuide V1.1 by Michael Ranner')
  22. writeln('Guide', '@NODE Main')
  23. writeln('Guide', '@WORDWRAP')
  24.  
  25. spaces = 0
  26. pushes = 0
  27. preformat = 0
  28. listing = 0
  29.  
  30. do until eof('HTML') = 1
  31.  
  32.     do until (srcline ~= '') | (eof('HTML') = 1)
  33.         srcline = readln('HTML')
  34.     end
  35.  
  36.     line = ''
  37.  
  38.     if index(srcline, '&') ~= 0 & listing = 0 then
  39.  
  40.         do while srcline ~= ''
  41.             parse var srcline start'&'token';'srcline
  42.             token = upper(token)
  43.  
  44.             select
  45.  
  46.                 when token = 'AMP' then line = line || start || '&'
  47.                 when token = 'GT' then line = line || start || '>'
  48.                 when token = 'LT' then line = line || start || '<'
  49.                 when token = 'QUOT' then line = line || start || '"'
  50.                 otherwise line = line || start || '&' || token
  51.  
  52.             end
  53.         end
  54.  
  55.     else line = srcline
  56.     
  57.     dstline = ''
  58.  
  59.     do while line ~= ''
  60.         parse var line start '<'token arg'>' line
  61.         token = compress(upper(token))
  62.  
  63.         select
  64.  
  65.             when token = '/XMP' or token = '/LISTING' then do 
  66.                 preformat = preformat - 1
  67.                 listing = 0
  68.             end
  69.  
  70.             when listing = 1 then do
  71.                 dstline = srcline
  72.                 leave
  73.             end
  74.  
  75.             when token = '/TITLE' then nop
  76.             when token = 'I' then dstline = dstline || start || '@{I}'
  77.             when token = '/I' then dstline = dstline || start || '@{UI}'
  78.             when token = 'B' then dstline = dstline || start || '@{B}'
  79.             when token = '/B' then dstline = dstline || start || '@{UB}'
  80.             when token = 'H1' | token = 'H2' then dstline = dstline || start || '0A0A'X
  81.             when token = '/H1' | token = '/H2' then dstline = dstline || start || '0A0A'X
  82.             when token = 'H3' | token = 'H5' then dstline = dstline || start || '0A'X || '@{I}'
  83.             when token = '/H3' | token = '/H5' then dstline = dstline || start || '@{UI}' || '0A'X
  84.             when token = 'H4' | token = 'H6' then dstline = dstline || start || '0A'X
  85.             when token = '/H4' | token = '/H6' then dstline = dstline || start || '0A'X
  86.             when token = 'BR' then dstline = dstline || start || '0A'X
  87.             when token = 'P' then dstline = dstline || start || '0A0A'X
  88.             when token = 'HR' then dstline = dstline || start || '0A'X || '@{U}' || copies(' ', 75) || '@{UU}' || '0A0A'X
  89.  
  90.             when token = 'UL' then do
  91.                 spaces = spaces + 4
  92.                 dstline = dstline || start || '0A'X || '@{LINDENT ' || spaces || '}' || '0A'X
  93.             end
  94.  
  95.             when token = '/UL' then do
  96.                 spaces = spaces - 4
  97.                 dstline = dstline || start || '0A'X || '@{LINDENT ' || spaces || '}' || '0A'X
  98.             end
  99.  
  100.             when token = 'OL' then do
  101.                 spaces = spaces + 4
  102.                 dstline = dstline || start || '0A'X || '@{LINDENT ' || spaces || '}' || '0A'X
  103.             end
  104.  
  105.             when token = '/OL' then do
  106.                 spaces = spaces - 4
  107.                 dstline = dstline || start || '0A'X || '@{LINDENT ' || spaces || '}' || '0A'X
  108.             end
  109.  
  110.             when token = 'LI' then dstline = dstline || start || '0A'X || '*  '
  111.  
  112.             when token = 'A' then do
  113.                 parse var arg token '=' node
  114.                 token = compress(upper(token))
  115.                 node = compress(node, '"')
  116.  
  117.                 if (token = 'HREF') & (node ~='') then do
  118.                     prot = upper(left(node, pos(':', node)))
  119.  
  120.                     select
  121.  
  122.                         when prot = 'HTTP:' then do
  123.                             node = pushNode(node)
  124.                         end
  125.  
  126.                         when prot = 'GOPHER:' then do
  127.                             node = pushNode(node)
  128.                         end
  129.  
  130.                         when prot = 'FTP:' then do
  131.                             node = pushNode(node)
  132.                         end
  133.  
  134.                         when prot = 'WAIS:' then do
  135.                             node = pushNode(node)
  136.                         end
  137.  
  138.                         when prot = 'NEWS:' then do
  139.                             node = pushNode(node)
  140.                         end
  141.  
  142.                         when prot = 'MAILTO:' then do
  143.                             node = pushNode(node)
  144.                         end
  145.  
  146.                         when prot = 'LOCALHOST:' then do
  147.                             node = left(node, lastpos('.', node)) || 'guide/MAIN'
  148.                             node = delstr(node, 1, lastpos('://', node) + 2)
  149.                         end
  150.                         
  151.                         otherwise node = left(node, lastpos('.', node)) || 'guide/MAIN'
  152.  
  153.                     end
  154.  
  155.                     dstline = dstline || start || '@{"'
  156.                 end
  157.             end
  158.  
  159.             when token = '/A' then dstline = dstline || start || '" LINK ' || node || '}'
  160.  
  161.             when token = 'IMG' then do
  162.                 parse var arg token '=' name token2 '=' alttext
  163.                 alttext = compress(alttext, '"')
  164.                 name = compress(name, '"')
  165.  
  166.                 if alttext ~= '' then dstline = dstline || start || '@{"[' || alttext || ']" LINK ' || name || '/MAIN}'
  167.                 else dstline = dstline || start || '@{"[Image]" LINK ' || name || '/MAIN}'
  168.             end
  169.  
  170.             when token = 'PRE' then preformat = preformat + 1
  171.             when token = '/PRE' then preformat = preformat - 1
  172.  
  173.             when token = 'XMP' | token = 'LISTING' then do 
  174.                 preformat = preformat + 1
  175.                 listing = 1
  176.             end
  177.  
  178.             when token = 'ADDRESS' | token = 'CITE' | token = 'EM' | token = 'VAR' then dstline = dstline || start || '@{I}'
  179.             when token = '/ADDRESS' | token = '/CITE' | token = '/EM' | token = '/VAR' then  dstline = dstline || start || '@{UI}'
  180.             when token = 'STRONG' then dstline = dstline || start || '@{B}'
  181.             when token = '/STRONG' then dstline = dstline || start || '@{UB}'
  182.             when token = 'BLOCKQUOTE' then dstline = dstline || start || '0A0A'X || '@{I}'
  183.             when token = 'BLOCKQUOTE' then dstline = dstline || start || '@{UI}' || '0A0A'X
  184.  
  185.             otherwise dstline = dstline || start
  186.         end
  187.     end
  188.  
  189.     if preformat = 1 then writeln('Guide', dstline)
  190.     else writech('Guide', dstline)
  191.  
  192. end
  193.  
  194. writeln('Guide', '0A0A'X || 'Converted at ' || date() || ' with RexxDoesHTML2AmigaGuide by Michael Ranner.' || '0A0A'X)
  195. writeln('Guide', '@ENDNODE')
  196.  
  197. do while pushes ~= 0
  198.     parse pull node
  199.     writeln('Guide', '@NODE ' || translate(node, '__', ':/') || '0A0A'X || node || '0A0A'X || @ENDNODE)
  200.     pushes = pushes - 1
  201. end
  202.  
  203. close('Guide')
  204. close('HTML')
  205.  
  206. exit
  207.  
  208. pushNode: procedure expose pushes
  209.     parse arg node
  210.     push node
  211.     pushes = pushes + 1
  212.     node = translate(node, '__', ':/')
  213.     return node
  214.